// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.linqingying.gitcode.pullrequest.data

import com.linqingying.gitcode.api.GCGQLRequests
import com.linqingying.gitcode.api.GCRepositoryCoordinates
import com.linqingying.gitcode.api.GitCodeApiRequestExecutor
import com.linqingying.gitcode.api.data.GCReaction
import com.linqingying.gitcode.api.data.GCReactionContent
import com.linqingying.gitcode.api.executeSuspend

interface GCReactionsService {
  suspend fun addReaction(subjectId: String, reaction: GCReactionContent): GCReaction
  suspend fun removeReaction(subjectId: String, reaction: GCReactionContent): GCReaction
}

internal class GCReactionsServiceImpl(
  private val requestExecutor: GitCodeApiRequestExecutor,
  private val repository: GCRepositoryCoordinates
) : GCReactionsService {
  override suspend fun addReaction(subjectId: String, reaction: GCReactionContent): GCReaction {
    val request = GCGQLRequests.Comment.addReaction(repository.serverPath, subjectId, reaction)
    return requestExecutor.executeSuspend(request)
  }

  override suspend fun removeReaction(subjectId: String, reaction: GCReactionContent): GCReaction {
    val request = GCGQLRequests.Comment.removeReaction(repository.serverPath, subjectId, reaction)
    return requestExecutor.executeSuspend(request)
  }
}
